<?php 
	require('includes/configure.php'); 
    require("includes/classes/class.Validator.php3");
	/* ADMIN DEFINED SETTINGS */
	$result = mysql_query("SELECT name, value FROM page_settings;");
	while($row = mysql_fetch_array($result))
	{
		$page_settings[$row['name']] = $row['value'];
	}
	/* ADMIN DEFINED SETTINGS END*/
	$titleStatus = "";
	$widthStatus = "";
	$allignStatus = "";
	$topBorderStatus = "";
	$rBorderStatus = "";
	$lBorderStatus = "";
	$sideBorderStatus = "";
	$bottomBorderStatus = "";
	
	if($_POST)
	{
		if($_POST['page_title'] != $page_settings['page_title'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['page_title']."' WHERE name = 'page_title'");
			if ($result > 0)
			{
				$titleStatus = "Old Title <strong>".$page_settings['page_title']."</strong> is changed to<strong>".$_POST['page_title']."</strong>";
			}
		}
		if($_POST['page_width_type'] == '2')
		{
			$type = 'px';
		}
		else
		{
			$type = '%';
		}
		if($_POST['page_width'] != $page_settings['page_width'])
		{
			if(($_POST['page_width_type'] != '2') && ($_POST['page_width'] > 100))
			{
				$widthStatus = "Cant have more than 100% width!!";
			}
			else
			{
				$result = mysql_query("UPDATE page_settings SET value = '".$_POST['page_width']."' WHERE name = 'page_width'");
				if ($result > 0)
				{
					$widthStatus = "Width Changed from <strong> ".$page_settings[page_width]." ".$page_settings[page_width_type]."</strong> to <strong>".$_POST[page_width]." ".$type."</strong>";
				}
			}
		}
		if($type != $page_settings['page_width_type'])
		{
			if(($_POST['page_width_type'] != '2') && ($_POST['page_width'] > 100))
			{
				$widthStatus = "Cant have more than 100% width!!";
			}
			else
			{
				$result = mysql_query("UPDATE page_settings SET value = '".$type."' WHERE name = 'page_width_type'");
				if ($result > 0)
				{
					$widthStatus = "Width Changed from <strong> ".$page_settings[page_width]." ".$page_settings[page_width_type]."</strong> to <strong>".$_POST[page_width]." ".$type."</strong>";
				}
			}
		}
		if($_POST['page_allign'] != $page_settings['page_allign'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['page_allign']."' WHERE name = 'page_allign'");
			if ($result > 0)
			{
				$allignStatus = "Alignment changed from <strong>".$page_settings['page_allign']."</strong> to <strong>".$_POST['page_allign']."</strong>";
			}
		}
		if($_POST['top_border'] != $page_settings['top_border'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['top_border']."' WHERE name = 'top_border'");
			if ($result > 0)
			{
				$topBorderStatus = "Top Border set to ".$_POST['top_border'];
			}
		}
		if($_POST['page_type'] != $page_settings['page_type'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['page_type']."' WHERE name = 'page_type'");
			if ($result > 0)
			{$pTypeStatus = "Page Border Type Set To :<strong>".$_POST['page_type']."</strong>";}
		}
		if($_POST['content_type'] != $page_settings['content_type'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['content_type']."' WHERE name = 'content_type'");
			if ($result > 0)
			{
				$cTypeStatus = "Set to <strong>".$_POST['content_type']."</strong>";
			}
		}
		if($_POST['content_type_header'] != $page_settings['content_type_header'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['content_type_header']."' WHERE name = 'content_type_header'");
			if ($result > 0)
			{
				$cTypeHStatus = "Set to <strong>".$_POST['content_type_header']."</strong>";
			}
		}
		if($_POST['content_type_footer'] != $page_settings['content_type_footer'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['content_type_footer']."' WHERE name = 'content_type_footer'");
			if ($result > 0)
			{
				$cTypeFStatus = "Set to <strong>".$_POST['content_type_footer']."</strong>";
			}
		}
		if($_POST['header_enabled'] != $page_settings['header_enabled'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['header_enabled']."' WHERE name = 'header_enabled'");
			if ($result > 0)
			{
				$headerEnabledStatus = "Header Enabled set to ".$_POST['header_enabled'];
			}
		}
		if($_POST['header_allign'] != $page_settings['header_allign'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['header_allign']."' WHERE name = 'header_allign'");
			if ($result > 0)
			{
				$hAllignStatus = "Alignment changed from <strong>".$page_settings['header_allign']."</strong> to <strong>".$_POST['header_allign']."</strong>";
			}
		}
		if($_POST['header_valign'] != $page_settings['header_valign'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['header_valign']."' WHERE name = 'header_valign'");
			if ($result > 0)
			{
				$hvAllignStatus = "Vertical Alignment changed from <strong>".$page_settings['header_valign']."</strong> to <strong>".$_POST['header_valign']."</strong>";
			}
		}
		if($_POST['header_type'] != $page_settings['header_type'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['header_type']."' WHERE name = 'header_type'");
			if ($result > 0)
			{
				$hTypeStatus = "Column right changed from ".$page_settings['header_type']."</strong> to <strong>".$_POST['header_type']."</strong>";
			}
		}
		if($_POST['footer_enabled'] != $page_settings['footer_enabled'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['footer_enabled']."' WHERE name = 'footer_enabled'");
			if ($result > 0)
			{
				$footerEnabledStatus = "Footer Enabled set to ".$_POST['footer_enabled'];
			}
		}
		if($_POST['footer_allign'] != $page_settings['footer_allign'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['footer_allign']."' WHERE name = 'footer_allign'");
			if ($result > 0)
			{
				$fAllignStatus = "Alignment changed from <strong>".$page_settings['footer_allign']."</strong> to <strong>".$_POST['footer_allign']."</strong>";
			}
		}
		if($_POST['footer_valign'] != $page_settings['footer_valign'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['footer_valign']."' WHERE name = 'footer_valign'");
			if ($result > 0)
			{
				$fvAllignStatus = "Vertical Alignment changed from <strong>".$page_settings['footer_valign']."</strong> to <strong>".$_POST['footer_valign']."</strong>";
			}
		}
		if($_POST['footer_type'] != $page_settings['footer_type'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['footer_type']."' WHERE name = 'footer_type'");
			if ($result > 0)
			{
				$fTypeStatus = "Column right changed from ".$page_settings['footer_type']."</strong> to <strong>".$_POST['footer_type']."</strong>";
			}
		}
		if($_POST['col_left_enabled'] != $page_settings['col_left_enabled'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['col_left_enabled']."' WHERE name = 'col_left_enabled'");
			if ($result > 0)
			{
				$clEnableStatus = "Column left changed from ".$page_settings['col_left_enabled']."</strong> to <strong>".$_POST['col_left_enabled']."</strong>";
			}
		}
		if($_POST['col_left_width'] != $page_settings['col_left_width'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['col_left_width']."' WHERE name = 'col_left_width'");
			if ($result > 0)
			{
				$clWidthStatus = "Column left changed from ".$page_settings['col_left_width']."</strong> to <strong>".$_POST['col_left_width']."</strong>";
			}
		}
		if($_POST['col_left_type'] != $page_settings['col_left_type'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['col_left_type']."' WHERE name = 'col_left_type'");
			if ($result > 0)
			{
				$clTypeStatus = "Column left changed from ".$page_settings['col_left_type']."</strong> to <strong>".$_POST['col_left_type']."</strong>";
			}
		}
		if($_POST['col_right_enabled'] != $page_settings['col_right_enabled'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['col_right_enabled']."' WHERE name = 'col_right_enabled'");
			if ($result > 0)
			{
				$crEnableStatus = "Column right changed from ".$page_settings['col_right_enabled']."</strong> to <strong>".$_POST['col_right_enabled']."</strong>";
			}
		}
		if($_POST['col_right_width'] != $page_settings['col_right_width'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['col_right_width']."' WHERE name = 'col_right_width'");
			if ($result > 0)
			{
				$crWidthStatus = "Column left changed from ".$page_settings['col_right_width']."</strong> to <strong>".$_POST['col_right_width']."</strong>";
			}
		}
		if($_POST['col_right_type'] != $page_settings['col_right_type'])
		{
			$result = mysql_query("UPDATE page_settings SET value = '".$_POST['col_right_type']."' WHERE name = 'col_right_type'");
			if ($result > 0)
			{
				$crTypeStatus = "Column right changed from ".$page_settings['col_right_type']."</strong> to <strong>".$_POST['col_right_type']."</strong>";
			}
		}
	}
	/* ADMIN DEFINED SETTINGS */
	$result = mysql_query("SELECT name, value FROM page_settings;");
	while($row = mysql_fetch_array($result))
	{
		$page_settings[$row['name']] = $row['value'];
	}
	/* ADMIN DEFINED SETTINGS END*/
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Site Templates</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<link rel="stylesheet" type="text/css" href="../borders.css">
<link rel="stylesheet" type="text/css" href="../headers.css">
<link rel="stylesheet" type="text/css" href="../footers.css">
<link rel="stylesheet" type="text/css" href="../buttons.css">
<link rel="stylesheet" type="text/css" href="../containers.css">
</head>
<body>
<center>
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="table-layout: fixed; background: #FFFFFF; ">
	<tr>
		<td style="background: #FFFFFF;">
			<?php require('../templates/borders/type_4_top.php'); ?>
			<?php require('../templates/borders/type_3_top.php'); ?>
			<form action="page_settings.php" method="post">
				<table width="100%" cellpadding="0" cellspacing="0" border="0" style="background: #FFFFFF; margin-bottom:16px;">
					<tr>
						<td class="admin_cell" valign="top"  width="250">Page Title</td>
						<td colspan="2"><input name="page_title" type="text" value="<?php echo $page_settings['page_title']; ?>"></td>
						<td><?php echo $titleStatus; ?></td>
					</tr>
					<tr>
						<td>Page Width</td>
						<td>
							<select name="page_width">
								<?php 
									$i=1;
									while($i <= 1600)
									{
										if ($i == $page_settings['page_width'])
										{
											echo '<option title="page_width" value="'.$i.'" selected>'.$i.'</option>';
										}
										else
										{
											echo '<option title="page_width" value="'.$i.'">'.$i.'</option>';
										}
										$i += 1;
									}
								?>
							</select>
						</td>
						<td>
							<select name="page_width_type">
								<?php 
								if ( $page_settings['page_width_type'] == 'px')
								{ 
								?>
								<option value="1">%</option>
								<option value="2" selected>px</option> 
								<?php 
								}
								else
								{ 
								?>
								<option  value="1" selected>%</option> 
								<option value="2">px</option>
								<?php 
								}
								?>
							</select>
						</td>
						<td><?php echo $widthStatus; ?></td>
					</tr>
					<tr>
						<td>Page Align</td>
						<td colspan="2">
							<select name="page_allign">
								<option <?php if($page_settings['page_allign'] == 'center') {echo "selected";} ?> value="center">center</option>
								<option <?php if($page_settings['page_allign'] == 'left') {echo "selected";} ?> value="left">left</option>
								<option <?php if($page_settings['page_allign'] == 'right') {echo "selected";} ?> value="right">right</option>
							</select>
						</td>
						<td><?php echo $allignStatus; ?></td>
					</tr>
					<tr>
						<td>Page Border Type</td>
						<td>
							<select name="page_type">
								<?php 
									$result = mysql_query("SELECT * FROM hc_com_borders WHERE page=1;");
									echo '<option value="0" selected>No Border</option>';
									while($row = mysql_fetch_array($result))
									{
										if ($row['id'] == $page_settings['page_type'])
										{
											echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
										}
										else
										{
											echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
										}
									}
								?>
							</select>
						</td>
						<td><?php echo $pTypeStatus; ?></td>
					</tr>
					<tr>
						<td colspan="4">----------------------------------------</td>
					</tr>
					<tr>
						<td>Main Content Border Type</td>
						<td>
							<select name="content_type">
								<?php 
									$result = mysql_query("SELECT * FROM hc_com_borders;");
									echo '<option value="0" selected>No Special Borders</option>';
									while($row = mysql_fetch_array($result))
									{
										if ($row['id'] == $page_settings['content_type'])
										{
											echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
										}
										else
										{
											echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
										}
									}
								?>
							</select>
						</td>
						<td><?php echo $cTypeStatus; ?></td>
					</tr>
					<tr>
						<td>Main Content Header Type</td>
						<td>
							<select name="content_type_header">
								<?php 
									$result = mysql_query("SELECT * FROM ".DB_PERFIX."com_headers;");
									echo '<option value="0" selected>No Special Header</option>';
									while($row = mysql_fetch_array($result))
									{
										if ($row['id'] == $page_settings['content_type_header'])
										{
											echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
										}
										else
										{
											echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
										}
									}
								?>
							</select>
						</td>
						<td><?php echo $cTypeHStatus; ?></td>
					</tr>
					<tr>
						<td>Main Content Footer Type</td>
						<td>
							<select name="content_type_footer">
								<?php 
									$result = mysql_query("SELECT * FROM ".DB_PERFIX."com_footers;");
									echo '<option value="0" selected>No Special Footer</option>';
									while($row = mysql_fetch_array($result))
									{
										if ($row['id'] == $page_settings['content_type_footer'])
										{
											echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
										}
										else
										{
											echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
										}
									}
								?>
							</select>
						</td>
						<td><?php echo $cTypeHStatus; ?></td>
					</tr>
					<tr>
						<td colspan="4">----------------------------------------</td>
					</tr>
					<tr>
						<td>Header Enabled</td>
						<td colspan="2">
							<select name="header_enabled">
								<option <?php if($page_settings['header_enabled'] == '1') {echo "selected";} ?> value="1">yes</option>
								<option <?php if($page_settings['header_enabled'] == '0') {echo "selected";} ?> value="0">no</option>
							</select>
						</td>
						<td><?php echo $headerEnabledStatus; ?></td>
					</tr>
					<tr>
						<td>Header Align</td>
						<td colspan="2">
							<select name="header_allign">
								<option <?php if($page_settings['header_allign'] == 'center') {echo "selected";} ?> value="center">center</option>
								<option <?php if($page_settings['header_allign'] == 'left') {echo "selected";} ?> value="left">left</option>
								<option <?php if($page_settings['header_allign'] == 'right') {echo "selected";} ?> value="right">right</option>
							</select>
						</td>
						<td><?php echo $hAllignStatus; ?></td>
					</tr>
					<tr>
						<td>Header Valign</td>
						<td colspan="2">
							<select name="header_valign">
								<option <?php if($page_settings['header_valign'] == 'top') {echo "selected";} ?> value="top">top</option>
								<option <?php if($page_settings['header_valign'] == 'middle') {echo "selected";} ?> value="middle">middle</option>
								<option <?php if($page_settings['header_valign'] == 'bottom') {echo "selected";} ?> value="bottom">bottom</option>
								<option <?php if($page_settings['header_valign'] == 'baseline') {echo "selected";} ?> value="baseline">baseline</option>
							</select>
						</td>
						<td><?php echo $hvAllignStatus; ?></td>
					</tr>
					<tr>
						<td>Header Border Type</td>
						<td>
							<select name="header_type">
								<?php 
									$result = mysql_query("SELECT * FROM hc_com_borders;");
									echo '<option value="0" selected>No Special Borders</option>';
									while($row = mysql_fetch_array($result))
									{
										if ($row['id'] == $page_settings['header_type'])
										{
											echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
										}
										else
										{
											echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
										}
									}
								?>
							</select>
						</td>
						<td><?php echo $hTypeStatus; ?></td>
					</tr>
					<tr>
						<td colspan="4">----------------------------------------</td>
					</tr>
					<tr>
						<td>Footer Enabled</td>
						<td colspan="2">
							<select name="footer_enabled">
								<option <?php if($page_settings['footer_enabled'] == '1') {echo "selected";} ?> value="1">yes</option>
								<option <?php if($page_settings['footer_enabled'] == '0') {echo "selected";} ?> value="0">no</option>
							</select>
						</td>
						<td><?php echo $footerEnabledStatus; ?></td>
					</tr>
					<tr>
						<td>Footer Align</td>
						<td colspan="2">
							<select name="footer_allign">
								<option <?php if($page_settings['footer_allign'] == 'center') {echo "selected";} ?> value="center">center</option>
								<option <?php if($page_settings['footer_allign'] == 'left') {echo "selected";} ?> value="left">left</option>
								<option <?php if($page_settings['footer_allign'] == 'right') {echo "selected";} ?> value="right">right</option>
							</select>
						</td>
						<td><?php echo $fAllignStatus; ?></td>
					</tr>
					<tr>
						<td>Footer Valign</td>
						<td colspan="2">
							<select name="footer_valign">
								<option <?php if($page_settings['footer_valign'] == 'top') {echo "selected";} ?> value="top">top</option>
								<option <?php if($page_settings['footer_valign'] == 'middle') {echo "selected";} ?> value="middle">middle</option>
								<option <?php if($page_settings['footer_valign'] == 'bottom') {echo "selected";} ?> value="bottom">bottom</option>
								<option <?php if($page_settings['footer_valign'] == 'baseline') {echo "selected";} ?> value="baseline">baseline</option>
							</select>
						</td>
						<td><?php echo $fvAllignStatus; ?></td>
					</tr>
					<tr>
						<td>Footer Border Type</td>
						<td>
							<select name="footer_type">
								<?php 
									$result = mysql_query("SELECT * FROM hc_com_borders;");
									echo '<option value="0" selected>No Special Borders</option>';
									while($row = mysql_fetch_array($result))
									{
										if ($row['id'] == $page_settings['footer_type'])
										{
											echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
										}
										else
										{
											echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
										}
									}
								?>
							</select>
						</td>
						<td><?php echo $fTypeStatus; ?></td>
					</tr>
					<tr>
						<td colspan="4">----------------------------------------</td>
					</tr>
					<tr>
						<td>Column Left Enabled</td>
						<td colspan="2">
							<select name="col_left_enabled">
								<option <?php if($page_settings['col_left_enabled'] == '1') {echo "selected";} ?> value="1">yes</option>
								<option <?php if($page_settings['col_left_enabled'] == '0') {echo "selected";} ?> value="0">no</option>
							</select>
						</td>
						<td><?php echo $clEnableStatus; ?></td>
					</tr>
					<tr>
						<td>Column Left Width</td>
						<td>
							<select name="col_left_width">
								<?php 
									$i=1;
									while($i <= 400)
									{
										if ($i == $page_settings['col_left_width'])
										{
											echo '<option value="'.$i.'" selected>'.$i.'</option>';
										}
										else
										{
											echo '<option value="'.$i.'">'.$i.'</option>';
										}
										$i ++;
									}
								?>
							</select>
						</td>
						<td><?php echo $clWidthStatus; ?></td>
					</tr>
					<tr>
						<td>Column Left Border Type</td>
						<td>
							<select name="col_left_type">
								<?php 
									$result = mysql_query("SELECT * FROM hc_com_borders;");
									echo '<option value="0" selected>No Special Borders</option>';
									while($row = mysql_fetch_array($result))
									{
										if ($row['id'] == $page_settings['col_left_type'])
										{
											echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
										}
										else
										{
											echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
										}
										$i ++;
									}
								?>
							</select>
						</td>
						<td><?php echo $clTypeStatus; ?></td>
					</tr>
					<tr>
						<td colspan="4">----------------------------------------</td>
					</tr>
					<tr>
						<td>Column Right Enabled</td>
						<td colspan="2">
							<select name="col_right_enabled">
								<option <?php if($page_settings['col_right_enabled'] == '1') {echo "selected";} ?> value="1">yes</option>
								<option <?php if($page_settings['col_right_enabled'] == '0') {echo "selected";} ?> value="0">no</option>
							</select>
						</td>
						<td><?php echo $crEnableStatus; ?></td>
					</tr>
					<tr>
						<td>Column Right Width</td>
						<td>
							<select name="col_right_width">
								<?php 
									$i=1;
									while($i <= 400)
									{
										if ($i == $page_settings['col_right_width'])
										{
											echo '<option value="'.$i.'" selected>'.$i.'</option>';
										}
										else
										{
											echo '<option value="'.$i.'">'.$i.'</option>';
										}
										$i ++;
									}
								?>
							</select>
						</td>
						<td><?php echo $crWidthStatus; ?></td>
					</tr>
					<tr>
						<td>Column Right Border Type</td>
						<td>
							<select name="col_right_type">
								<?php 
									$result = mysql_query("SELECT * FROM hc_com_borders;");
									echo '<option value="0" selected>No Special Borders</option>';
									while($row = mysql_fetch_array($result))
									{
										if ($row['id'] == $page_settings['col_right_type'])
										{
											echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
										}
										else
										{
											echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
										}
									}
								?>
							</select>
						</td>
						<td><?php echo $crTypeStatus; ?></td>
					</tr>
					<tr>
						<td colspan="4"><input type="submit" value="Submit Changes"></td>
					</tr>
				</table>
			</form>
			<?php require('../templates/borders/type_3_bot.php'); ?>
			<?php require('../templates/borders/type_4_bot.php'); ?>
		</td>
	</tr>
</table>
</center>
</body>
</html>